﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using WindowsGame1.GameMain;
using WindowsGame1.Interface;
using WindowsGame1.Objects3D;
using WindowsGame1.Operations;

namespace WindowsGame1.Windows
{
    class MainGame : Canvas
    {
        private Map _mapa;

        public MainGame(Game game)
        {
            Game = game;
            Width = game.Window.ClientBounds.Width;
            Height = game.Window.ClientBounds.Height;
            Buttons = new Botoes();

            Camera.Initialize(((Core)Game).Graphics.GraphicsDevice, new Vector3(1.0f, 0.2f, 1.0f), Vector3.Zero);
        }

        public override void LoadContent(ContentManager content)
        {
            //inicializa o mapa de acordo com os seus parametros
            //_mapa = new Map(((Core)Game).Graphics.GraphicsDevice, content);

            _mapa = new Map(((Core)Game).Graphics.GraphicsDevice, content);
            _mapa.load("Content/Map/map.txt");
            Camera.Initialize(((Core)Game).Graphics.GraphicsDevice, new Vector3(_mapa.getStart()[0], 0.2f, _mapa.getStart()[1]), Vector3.Zero);
        }

        public override void Update(GameTime gameTime)
        {
            Camera.savePosition();
            Camera.Update(gameTime);
            switch(Camera.collided(_mapa)){
                case Map.CODE_WALL:
                    Camera.restoreSavedPosition();
                    break;
                case Map.CODE_EXTRATIME:
                    StaticGUi.Time.RunningTime -= 5000;
                    break;
                case Map.CODE_EXIT:
                    ((Core)Game).LoadEndGame();
                    break;
            }
        }

        public override void Render(SpriteBatch renderTarget)
        {
            _mapa.Draw();
        }
    }
}
